const customersDao = require("../dao/customersDao");

exports.getList = async (req, res) => {
  const customers = await customersDao.getAll();
  res.json(customers);
};

exports.add = async (req, res) => {
  const customer = req.body;
  const result = await customersDao.add(customer);
  res.json({ code: 200, message: "添加成功", customer: result });
};

exports.update = async (req, res) => {
  const { id } = req.params;
  const customer = req.body;
  const result = await customersDao.update(id, customer);
  res.json({ code: 200, message: "更新成功", customer: result });
};

exports.remove = async (req, res) => {
  const { id } = req.params;
  await customersDao.remove(id);
  res.json({ code: 200, message: "删除成功" });
};

exports.getBalanceDetails = async (req, res) => {
  const { id } = req.params;
  const details = await customersDao.getBalanceDetails(id);
  res.json(details);
};
